package com.jzr.task.job.shiyan;

import com.jzr.task.db1.mapper.MyPrimaryMapper;
import com.jzr.task.db1.mapper.TBedMapper;
import com.jzr.task.db1.model.TBed;
import com.jzr.task.db2.mapper.ShiyanMapper;
import com.jzr.task.db2.model.ShiyanBed;
import com.jzr.task.job.BaseJob;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component("Shiyan.SyncBed")
public class ShiyanSyncBed extends BaseJob {
    @Autowired
    private ShiyanMapper shiyanMapper;

    @Autowired
    private MyPrimaryMapper primaryMapper;

    @Autowired
    private TBedMapper bedMapper;

    @Override
    public void process() throws Exception {
        //同步床位
        List<ShiyanBed> list = shiyanMapper.getBedList();
        for(ShiyanBed p : list){
            TBed bed = new TBed();
            BeanUtils.copyProperties(p,bed);
            bed.setUpdateTime(LocalDateTime.now());
            Integer id = primaryMapper.getBedId(p.getDeptCode(),p.getRoomCode(),p.getBedCode().trim());
            if(id == null){
                bedMapper.insert(bed);
            }else{
                bed.setId(id);
                bedMapper.updateById(bed);
            }
        }
    }
}